package com.sk.skplanet.commute.controllers;

import java.util.ArrayList;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.view.ContextThemeWrapper;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;

import com.sk.skplanet.commute.R;
import com.sk.skplanet.commute.actions.API_searchBus;
import com.sk.skplanet.commute.actions.API_searchTmap;
import com.sk.skplanet.commute.actions.DeleteTask;
import com.sk.skplanet.commute.actions.InsertTask;
import com.sk.skplanet.commute.actions.RegisteringTask;
import com.sk.skplanet.commute.daofactory.DBdownloadTask;
import com.sk.skplanet.commute.daofactory.LocalDaoFactory;
import com.sk.skplanet.commute.layouts.DialogLayout;
import com.sk.skplanet.commute.layouts.ViewLayout;
import com.sk.skplanet.commute.views.PointList;
import com.sk.skplanet.commute.views.RouteList;
import com.sk.skplanet.commute.vo.BusServerVo;
import com.sk.skplanet.commute.vo.Data;
import com.sk.skplanet.commute.vo.Point;
import com.sk.skplanet.commute.vo.Route;
import com.sk.skplanet.commute.vo.StopInfo;
import com.skp.Tmap.TMapView;

public class DialogController {

	/** 삭제 다이얼로그 */
	public static Dialog createDeleteDialog(final Context context, BusServerVo busVo, View v) {
		final AlertDialog ad = new AlertDialog.Builder(new ContextThemeWrapper(context,
				android.R.style.Theme_DeviceDefault_Light_Dialog)).create();
		final BusServerVo voToPass = busVo;
		final View view = v;

		LinearLayout layout_dialog_route = DialogLayout.createDialogLinearLayout(context);
		layout_dialog_route.setMinimumHeight(0);
		layout_dialog_route.addView(DialogLayout.createDialogTitleLayout(context,
				R.string.textview_dialog_delete_title, null, null, null));

		// final EditText edittext_dialog_route = ViewLayout.createEditText(context, Data.EDITTEXT_NONE, null);
		// layout_dialog_route.addView(edittext_dialog_route);
		{
			Button button_summit = ViewLayout.createButton(context, R.string.button_dialog_summit);
			button_summit.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// if (Data.memberData.getRoutes() == null) Data.memberData.setRoutes(new ArrayList<Route>());
					new DeleteTask(context, voToPass).execute(view);

					// Intent intent = new Intent(context, RouteList.class);
					// context.startActivity(intent);
					// ((Activity) context).finish();
					ad.dismiss();
				}
			});
			Button button_cancel = ViewLayout.createButton(context, R.string.button_dialog_cancel);
			button_cancel.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					ad.dismiss();
				}
			});
			layout_dialog_route.addView(DialogLayout.createDialogButtonLayout(context, button_summit, button_cancel));
		}
		ad.setView(layout_dialog_route);
		return ad;
	}

	/** 삭제 다이얼로그 - 로컬디비용으로 수정 */
	public static Dialog createDeletePointDialogAtLocal(final Context context, final View v, final long id) {
		final AlertDialog ad = new AlertDialog.Builder(new ContextThemeWrapper(context,
				android.R.style.Theme_DeviceDefault_Light_Dialog)).create();

		LinearLayout layout_dialog_route = DialogLayout.createDialogLinearLayout(context);
		layout_dialog_route.setMinimumHeight(0);
		layout_dialog_route.addView(DialogLayout.createDialogTitleLayout(context,
				R.string.textview_dialog_delete_title, null, null, null));

		{
			Button button_summit = ViewLayout.createButton(context, R.string.button_dialog_summit);
			button_summit.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					LocalDaoFactory.deletePoint(id);
					
					Intent intent = new Intent(context, RouteList.class);
					context.startActivity(intent);
					((Activity) context).finish();
					ad.dismiss();
				}
			});
			Button button_cancel = ViewLayout.createButton(context, R.string.button_dialog_cancel);
			button_cancel.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					ad.dismiss();
				}
			});
			layout_dialog_route.addView(DialogLayout.createDialogButtonLayout(context, button_cancel, button_summit));
		}
		ad.setView(layout_dialog_route);
		return ad;
	}


	/** 루트 추가 다이얼로그 */
	public static Dialog createRouteDialog(final Context context) {
		final AlertDialog ad = new AlertDialog.Builder(new ContextThemeWrapper(context,
				android.R.style.Theme_DeviceDefault_Light_Dialog)).create();

		LinearLayout layout_dialog_route = DialogLayout.createDialogLinearLayout(context);
		layout_dialog_route.setMinimumHeight(0);
		layout_dialog_route.addView(DialogLayout.createDialogTitleLayout(context, R.string.textview_dialog_route_title,
				null, null, null));

		final EditText edittext_dialog_route = ViewLayout.createEditText(context, Data.EDITTEXT_NONE, null);
		layout_dialog_route.addView(edittext_dialog_route);
		{
			Button button_summit = ViewLayout.createButton(context, R.string.button_dialog_summit);
			button_summit.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					// if (Data.memberData.getRoutes() == null) Data.memberData.setRoutes(new ArrayList<Route>());
					Route route = new Route(Data.memberData.getRoutes().size() + 1, edittext_dialog_route.getText()
							.toString(), Data.memberData.getId());
					Data.memberData.addRoute(route);
					new InsertTask(context, route).execute();

					Intent intent = new Intent(context, RouteList.class);
					context.startActivity(intent);
					((Activity) context).finish();
					ad.dismiss();
				}
			});
			Button button_cancel = ViewLayout.createButton(context, R.string.button_dialog_cancel);
			button_cancel.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					ad.dismiss();
				}
			});
			layout_dialog_route.addView(DialogLayout.createDialogButtonLayout(context, button_summit, button_cancel));
		}
		ad.setView(layout_dialog_route);
		return ad;
	}

	/** 지역 추가 다이얼로그 - 로컬디비용으로 수정됨. */
	public static Dialog createPointDialogAtLocal(final Context context) {
		final AlertDialog ad = new AlertDialog.Builder(new ContextThemeWrapper(context,
				android.R.style.Theme_DeviceDefault_Light_Dialog)).create();

		LinearLayout layout_dialog_route = DialogLayout.createDialogLinearLayout(context);
		layout_dialog_route.setMinimumHeight(0);
		layout_dialog_route.addView(DialogLayout.createDialogTitleLayout(context, R.string.textview_dialog_route_title,
				null, null, null));

		final EditText edittext_dialog_route = ViewLayout.createEditText(context, Data.EDITTEXT_NONE, null);
		layout_dialog_route.addView(edittext_dialog_route);
		{
			Button button_summit = ViewLayout.createButton(context, R.string.button_dialog_summit);
			button_summit.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// if (Data.memberData.getRoutes() == null) Data.memberData.setRoutes(new ArrayList<Route>());
					LocalDaoFactory.insertPoint(edittext_dialog_route.getText().toString());
					//new InsertTask(context, route).execute();

					Intent intent = new Intent(context, RouteList.class);
					context.startActivity(intent);
					((Activity) context).finish();
					ad.dismiss();
				}
			});
			Button button_cancel = ViewLayout.createButton(context, R.string.button_dialog_cancel);
			button_cancel.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					ad.dismiss();
				}
			});
			layout_dialog_route.addView(DialogLayout.createDialogButtonLayout(context, button_cancel, button_summit));
		}
		ad.setView(layout_dialog_route);
		return ad;
	}
	
	/** 포인트 추가 다이얼로그 */
	public static Dialog createPointDialog(final Context context, final int routePosition) {
		// 포인트 다이얼로그 레이아웃 설정 부분
		final Route route = Data.memberData.getRoutes().get(routePosition);
		final AlertDialog ad = new AlertDialog.Builder(new ContextThemeWrapper(context,
				android.R.style.Theme_DeviceDefault_Light_Dialog)).create();

		LinearLayout layout_dialog_point = DialogLayout.createDialogLinearLayout(context);
		layout_dialog_point.setMinimumHeight(0);
		layout_dialog_point.addView(DialogLayout.createDialogTitleLayout(context, R.string.textview_dialog_point_title,
				null, null, null));

		// 포인트 텍스트뷰 설정 부분
		final EditText edittext_dialog_point = ViewLayout.createEditText(context, Data.EDITTEXT_NONE, null);
		layout_dialog_point.addView(edittext_dialog_point);

		{
			Button button_summit = ViewLayout.createButton(context, R.string.button_dialog_summit);
			button_summit.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Point point = new Point(route.getPoints().size() + 1, edittext_dialog_point.getText().toString(),
							route.getId());
					route.addPoint(point);
					new InsertTask(context, point).execute();

					Intent intent = new Intent(context, PointList.class);
					intent.putExtra("routePosition", routePosition);
					context.startActivity(intent);
					((Activity) context).finish();
				}
			});
			Button button_cancel = ViewLayout.createButton(context, R.string.button_dialog_cancel);
			button_cancel.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					ad.dismiss();
				}
			});
			layout_dialog_point.addView(DialogLayout.createDialogButtonLayout(context, button_summit, button_cancel));
		}
		ad.setView(layout_dialog_point);
		return ad;
	}
	
	public static Dialog createStationDialog(final Context context, final int routePostion, final int pointPosition) {

		final AlertDialog ad = new AlertDialog.Builder(new ContextThemeWrapper(context,
				android.R.style.Theme_DeviceDefault_Light_Dialog)).create();
		final ScrollView scrollView = new ScrollView(context); // 정류장정보 리스트 뷰 컨테이너 부분
		final TMapView TmapView = TmapViewController.createTmapView(context); // 티맵뷰

		final LinearLayout layout_dialog_stopinfo = DialogLayout.createDialogLinearLayout(context); // 껍데기

		final LinearLayout layout_dialog_station = DialogLayout.createDialogListView(context); // 리스트 레이아웃
		final LinearLayout layout_dialog_title = DialogLayout.createDialogTitleLayout(context,
				R.string.textview_dialog_station_title, layout_dialog_stopinfo, scrollView, TmapView); // 타이틀

		layout_dialog_stopinfo.addView(layout_dialog_title);

		scrollView.addView(layout_dialog_station);

		// 포인트 에딧텍스트 설정 부분
		{
			final EditText edittext_dialog_stopinfo = ViewLayout.createEditText(context, Data.EDITTEXT_SEARCH,
					R.string.textview_dialog_station_edittext);
			edittext_dialog_stopinfo.setOnEditorActionListener(new OnEditorActionListener() {
				@Override
				public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
					// TODO Auto-generated method stub
					{
						layout_dialog_station.removeAllViews(); // remove previous search items
						if (edittext_dialog_stopinfo.getText().toString().equals("")) return false;
						Cursor result = LocalDaoFactory.selectIDQuery(edittext_dialog_stopinfo.getText().toString(),
								Data.TABLE_STATION);
						result.moveToFirst();
						while (!result.isAfterLast()) { // 실제 필요한 작업 처리
							final Route route = Data.memberData.getRoutes().get(routePostion);
							final Point point = route.getPoints().get(pointPosition);
							final String stationNameKor = result.getString(1);
							final String stationId = result.getString(0);

							// 뷰 레이아웃 추가
							LinearLayout layout_station = DialogLayout.createDialogViewLayout(context, ad, point,
									stationNameKor, stationId, Data.DIALOG_STATION);
							layout_station.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									// TODO Auto-generated method stub
									if (point.getStopInfos() == null) point.setStopInfos(new ArrayList<StopInfo>());
									StopInfo stopinfo = new StopInfo(point.getStopInfos().size() + 1, stationId,
											stationNameKor, "", "", "", point.getId());

									new API_searchBus(context, routePostion, pointPosition, stopinfo).execute(
											"getRouteByStation", stationId); // 호출 함수 이름, 호출 함수 인자
									// (1:공항, 3:간선, 4:지선, 5:순환, 6:광역, 7:인천, 8:경기, 9:폐지, 0:공용)
									ad.dismiss();
								}
							});

							layout_dialog_station.addView(layout_station);

							result.moveToNext();
						}
					}
					{
						new API_searchTmap(context, TmapView, ad, routePostion, pointPosition, layout_dialog_stopinfo,
								scrollView, layout_dialog_title).execute("getStationByName", edittext_dialog_stopinfo
								.getText().toString());
					}
					InputMethodManager imm = (InputMethodManager) context
							.getSystemService(Context.INPUT_METHOD_SERVICE);
					imm.hideSoftInputFromWindow(edittext_dialog_stopinfo.getWindowToken(), 0);

					return false;
				}
			});
			{
				android.view.ViewGroup.LayoutParams layoutParams_edittext_dialog_stopinfo = new LayoutParams(
						LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
				edittext_dialog_stopinfo.setLayoutParams(layoutParams_edittext_dialog_stopinfo);
			}
			layout_dialog_stopinfo.addView(edittext_dialog_stopinfo);
		}
		if (layout_dialog_title.getTag() == Data.DIALOG_LIST) {
			layout_dialog_stopinfo.addView(scrollView);
		} else if (layout_dialog_title.getTag() == Data.DIALOG_MAP) {
			layout_dialog_stopinfo.addView(TmapView);
		}

		ad.setView(layout_dialog_stopinfo);
		return ad;
	}

	public static Dialog createStationDialogAtLocal(final Context context, final int pointId) {
		final AlertDialog ad = new AlertDialog.Builder(new ContextThemeWrapper(context,
				android.R.style.Theme_DeviceDefault_Light_Dialog)).create();
		final ScrollView scrollView = new ScrollView(context); // 정류장정보 리스트 뷰 컨테이너 부분
		final TMapView TmapView = TmapViewController.createTmapView(context); // 티맵뷰

		final LinearLayout layout_dialog_stopinfo = DialogLayout.createDialogLinearLayout(context); // 껍데기

		final LinearLayout layout_dialog_station = DialogLayout.createDialogListView(context); // 리스트 레이아웃
		final LinearLayout layout_dialog_title = DialogLayout.createDialogTitleLayout(context,
				R.string.textview_dialog_station_title, layout_dialog_stopinfo, scrollView, TmapView); // 타이틀

		layout_dialog_stopinfo.addView(layout_dialog_title);

		scrollView.addView(layout_dialog_station);

		// 포인트 에딧텍스트 설정 부분
		{
			final EditText edittext_dialog_stopinfo = ViewLayout.createEditText(context, Data.EDITTEXT_SEARCH,
					R.string.textview_dialog_station_edittext);
			edittext_dialog_stopinfo.setOnEditorActionListener(new OnEditorActionListener() {
				@Override
				public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
					{
						layout_dialog_station.removeAllViews(); // remove previous search items
						
						if (edittext_dialog_stopinfo.getText().toString().equals("")) return false; // empty string validation
						
						// Finding bus stop
						Cursor result = LocalDaoFactory.selectIDQuery(edittext_dialog_stopinfo.getText().toString(),
								Data.TABLE_STATION);
						result.moveToFirst();
						while (!result.isAfterLast()) { // 실제 필요한 작업 처리
							final Point point = LocalDaoFactory.getPoint(pointId);
							final String stationNameKor = result.getString(1);
							final String stationId = result.getString(0);

							// 검색결과 뷰 레이아웃 추가
							LinearLayout layout_station = DialogLayout.createDialogViewLayout(context, ad, point,
									stationNameKor, stationId, Data.DIALOG_STATION);
							
							// 이벤트 할당 - 추가 이벤트
							layout_station.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									if (point.getStopInfos() == null) point.setStopInfos(new ArrayList<StopInfo>());
									StopInfo stopinfo = new StopInfo(0, stationId,
											stationNameKor, "", "", "", point.getId());

									new API_searchBus(context, pointId, stopinfo).execute(
											"getRouteByStation", stationId); // 호출 함수 이름, 호출 함수 인자
									// (1:공항, 3:간선, 4:지선, 5:순환, 6:광역, 7:인천, 8:경기, 9:폐지, 0:공용)
									ad.dismiss();
								}
							});

							layout_dialog_station.addView(layout_station);

							result.moveToNext();
						}
					}
					{
						new API_searchTmap(context, TmapView, ad, pointId, layout_dialog_stopinfo,
								scrollView, layout_dialog_title).execute("getStationByName", edittext_dialog_stopinfo
								.getText().toString());
					}
					InputMethodManager imm = (InputMethodManager) context
							.getSystemService(Context.INPUT_METHOD_SERVICE);
					imm.hideSoftInputFromWindow(edittext_dialog_stopinfo.getWindowToken(), 0);

					return false;
				}
			});
			{
				android.view.ViewGroup.LayoutParams layoutParams_edittext_dialog_stopinfo = new LayoutParams(
						LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
				edittext_dialog_stopinfo.setLayoutParams(layoutParams_edittext_dialog_stopinfo);
			}
			layout_dialog_stopinfo.addView(edittext_dialog_stopinfo);
		}
		if (layout_dialog_title.getTag() == Data.DIALOG_LIST) {
			layout_dialog_stopinfo.addView(scrollView);
		} else if (layout_dialog_title.getTag() == Data.DIALOG_MAP) {
			layout_dialog_stopinfo.addView(TmapView);
		}

		ad.setView(layout_dialog_stopinfo);
		return ad;
	}

	
	public static Dialog createBusDialog(final Context context, final int routePosition, final int pointPosition,
			final StopInfo stopInfo) {
		final AlertDialog ad = new AlertDialog.Builder(new ContextThemeWrapper(context,
				android.R.style.Theme_DeviceDefault_Light_Dialog)).create();

		LinearLayout layout_dialog_stopinfo2 = DialogLayout.createDialogLinearLayout(context); // 껍데기 레이아웃
		layout_dialog_stopinfo2.addView(DialogLayout.createDialogTitleLayout(context,
				R.string.textview_dialog_bus_title, null, null, null)); // 타이틀
		ScrollView scrollView = new ScrollView(context); // 버스정보 리스트 뷰 컨테이너 부분
		final LinearLayout layout_dialog_bus = DialogLayout.createDialogListView(context); // 리스트 뷰 컨테이너 레이아웃
		scrollView.addView(layout_dialog_bus);
		layout_dialog_bus.removeAllViews();

		for (int api_businfo_pos = 0; api_businfo_pos < Data.api_businfos.size(); api_businfo_pos++) {
			final String busNumberKor = Data.api_businfos.get(api_businfo_pos).getBusName();
			final String busType = Data.api_businfos.get(api_businfo_pos).getBusType();
			final String busId = Data.api_businfos.get(api_businfo_pos).getBusId();
			// 실제 필요한 작업 처리
			// (1:공항, 3:간선, 4:지선, 5:순환, 6:광역, 7:인천, 8:경기, 9:폐지, 0:공용)
			Route route = Data.memberData.getRoutes().get(routePosition);
			final Point point = route.getPoints().get(pointPosition);

			// 포인트 객체에 busId 정보 넣음

			if (!("0".equals(busType) || "9".equals(busType))) {
				LinearLayout layout_bus = DialogLayout.createDialogViewLayout(context, ad, point, busNumberKor,
						busType, Data.DIALOG_BUS);
				layout_bus.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						if (point.getStopInfos() != null) {

							// StopInfo stopinfo = point.getStopInfos().get(point.getStopInfos().size() - 1);
							stopInfo.setBus_id(busId);
							stopInfo.setBus_name(busNumberKor);
							stopInfo.setBus_type(busType);
							point.getStopInfos().add(stopInfo);
							new InsertTask(context, stopInfo).execute();

							Intent intenPointList = new Intent(context, PointList.class);
							intenPointList.putExtra("routePosition", routePosition);
							context.startActivity(intenPointList);
							((Activity) context).finish();

							ad.dismiss();
						}
						ad.dismiss();
					}
				});
				layout_dialog_bus.addView(layout_bus);
			}
		}
		layout_dialog_stopinfo2.addView(scrollView);

		ad.setView(layout_dialog_stopinfo2);
		return ad;
	}
	
	public static Dialog createBusDialogAtLocal(final Context context, final int pointId, final StopInfo stopInfo) {
		final AlertDialog ad = new AlertDialog.Builder(new ContextThemeWrapper(context,
				android.R.style.Theme_DeviceDefault_Light_Dialog)).create();

		LinearLayout layout_dialog_stopinfo2 = DialogLayout.createDialogLinearLayout(context); // 껍데기 레이아웃
		layout_dialog_stopinfo2.addView(DialogLayout.createDialogTitleLayout(context,
				R.string.textview_dialog_bus_title, null, null, null)); // 타이틀
		ScrollView scrollView = new ScrollView(context); // 버스정보 리스트 뷰 컨테이너 부분
		final LinearLayout layout_dialog_bus = DialogLayout.createDialogListView(context); // 리스트 뷰 컨테이너 레이아웃
		scrollView.addView(layout_dialog_bus);
		layout_dialog_bus.removeAllViews();

		for (int api_businfo_pos = 0; api_businfo_pos < Data.api_businfos.size(); api_businfo_pos++) {
			final String busNumberKor = Data.api_businfos.get(api_businfo_pos).getBusName();
			final String busType = Data.api_businfos.get(api_businfo_pos).getBusType();
			final String busId = Data.api_businfos.get(api_businfo_pos).getBusId();
			// 실제 필요한 작업 처리
			// (1:공항, 3:간선, 4:지선, 5:순환, 6:광역, 7:인천, 8:경기, 9:폐지, 0:공용)
			final Point point = LocalDaoFactory.getPoint(pointId);

			// 포인트 객체에 busId 정보 넣음

			if (!("0".equals(busType) || "9".equals(busType))) {
				LinearLayout layout_bus = DialogLayout.createDialogViewLayout(context, ad, point, busNumberKor,
						busType, Data.DIALOG_BUS);
				layout_bus.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						if (point.getStopInfos() != null) {
							// StopInfo stopinfo = point.getStopInfos().get(point.getStopInfos().size() - 1);
							//stopInfo.setBus_id(busId);
							//stopInfo.setBus_name(busNumberKor);
							//stopInfo.setBus_type(busType);
							
							//point.getStopInfos().add(stopInfo);
							//new InsertTask(context, stopInfo).execute();

							LocalDaoFactory.insertStopinfo(stopInfo.getStop_id(), stopInfo.getStop_name(), busId, busNumberKor, busType, pointId);
							
							Intent intenPointList = new Intent(context, PointList.class);
							intenPointList.putExtra("pointId", (int)point.getId());
							context.startActivity(intenPointList);
							((Activity) context).finish();

							ad.dismiss();
						}
						ad.dismiss();
					}
				});
				layout_dialog_bus.addView(layout_bus);
			}
		}
		layout_dialog_stopinfo2.addView(scrollView);

		ad.setView(layout_dialog_stopinfo2);
		return ad;
	}

	public static Dialog createMemberjoinDialog(final Context context) {
		final AlertDialog ad = new AlertDialog.Builder(new ContextThemeWrapper(context,
				android.R.style.Theme_DeviceDefault_Light_Dialog)).create();
		LinearLayout layout_dialog_stopinfo2 = DialogLayout.createDialogLinearLayout(context); // 껍데기 레이아웃
		layout_dialog_stopinfo2.setMinimumHeight(0);
		layout_dialog_stopinfo2.addView(DialogLayout.createDialogTitleLayout(context,
				R.string.textview_memberlogin_memberjoin, null, null, null)); // 타이틀

		final LinearLayout layout_dialog_bus = DialogLayout.createDialogListView(context); // 리스트 뷰 컨테이너 레이아웃
		layout_dialog_bus.setMinimumHeight(0);
		final EditText edittext_memberlogin_email = ViewLayout.createEditText(context, Data.EDITTEXT_NONE,
				R.string.edittext_memberlogin_email);
		final EditText edittext_memberlogin_password = ViewLayout.createEditText(context, Data.EDITTEXT_NONE,
				R.string.edittext_memberlogin_password);
		final EditText edittext_memberlogin_repassword = ViewLayout.createEditText(context, Data.EDITTEXT_NONE,
				R.string.edittext_memberlogin_repassword);
		layout_dialog_bus.addView(edittext_memberlogin_email);
		layout_dialog_bus.addView(edittext_memberlogin_password);
		layout_dialog_bus.addView(edittext_memberlogin_repassword);

		Button button_summit = ViewLayout.createButton(context, R.string.button_dialog_summit);
		button_summit.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				String email = edittext_memberlogin_email.getText().toString();
				String password = edittext_memberlogin_password.getText().toString();

				if (email.length() < 4 || password.length() < 4) {
					Toast.makeText(context, "모든 값을 입력하세요.", Toast.LENGTH_SHORT).show();
				} else if (!password.equals(edittext_memberlogin_repassword.getText().toString())) {
					Toast.makeText(context, "비밀번호가 맞지 않습니다.", Toast.LENGTH_SHORT).show();
				} else {
					ad.dismiss();
					RegisteringTask rTask = new RegisteringTask(context, email, password);
					rTask.execute();
				}
			}
		});
		layout_dialog_bus.addView(button_summit);
		layout_dialog_stopinfo2.addView(layout_dialog_bus);
		ad.setView(layout_dialog_stopinfo2);
		return ad;
	}

	public static Dialog createDBdownloadDialog(final Context context) {

		final AlertDialog ad = new AlertDialog.Builder(new ContextThemeWrapper(context,
				android.R.style.Theme_DeviceDefault_Light_Dialog)).create();

		LinearLayout layout_dialog_route = DialogLayout.createDialogLinearLayout(context);
		layout_dialog_route.setMinimumHeight(0);
		layout_dialog_route.addView(DialogLayout.createDialogTitleLayout(context,
				R.string.textview_dialog_dbdownload_title, null, null, null));

		{
			Button button_summit = ViewLayout.createButton(context, R.string.button_dialog_summit);
			button_summit.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					new DBdownloadTask(context).execute();
					ad.dismiss();
				}
			});
			Button button_cancel = ViewLayout.createButton(context, R.string.button_dialog_cancel);
			button_cancel.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					ad.dismiss();
				}
			});
			layout_dialog_route.addView(DialogLayout.createDialogButtonLayout(context, button_summit, button_cancel));
		}
		ad.setView(layout_dialog_route);
		return ad;
	}

}
